import VueRouter from "vue-router";

import Login from "../page/Login"
import Register from "../page/Register"
import List from "../view/List"


import Menu_child from "../view/Menu_ca/Menu_child"
const Bingtu =() =>import("../view/Menu_ca/bingtu")
const Chanping =()=>import('../view/Menu_ca/chanping')
const Liebiao  =()=>import('../view/Menu_ca/liebiao/liebiao')
const Fenlei  =()=>import('../view/Menu_ca/cgy/fenlei')

const Guanggao  =()=>import('../view/Menu_ca/guanggao')
const Guang_list =()=>import('../view/Menu_ca/guang_ca/guang_list')
const Guang_cgy =()=>import('../view/Menu_ca/guang_ca/guang_cgy')





let router = new VueRouter({
    routes:[
        {path:'/',redirect:'/login'},
        {
            path:'/login',
            name:'login',
            component:Login,

            meta:{
                isAuthentication:true //是否需要鉴权
            }
        },
        {
            path:'/Register',
            name:'Register',
            component:Register
        },
        {
            path:'/list',
            name:'list',
            component:List,
            children:[
                {path:'/',redirect:'Menu_child'},
                {
                    path:'/Menu_child',
                    name:'menu_child',
                    component:Menu_child,
                    children:[
                        {
                            path:"/bingtu",
                            name:'bingtu',
                            component:Bingtu
                        }
                    ]
                },
                
                {
                    path:'/chanping',
                    name:'chanping',
                    component:Chanping,
                    children:[
                        {
                            path:'liebiao',
                            name:'liebiao',
                            component:Liebiao
                        },
                        {
                            path:'cgy',
                            name:'cgy',
                            component:Fenlei
                        },
                    ]
                },
                {
                    path:'/guanggao',
                    name:'guanggao',
                    component:Guanggao,
                    children:[
                        {
                            path:'guang_list',
                            name:'guang_list',
                            component:Guang_list
                        },
                        {
                            path:'guang_cgy',
                            name:'guang_cgy',
                            component:Guang_cgy
                        }
                    ]
                    
                }
            ],
            redirect:'/Menu_child',
            
            
            
            beforeEnter(to,from,next){
                if(sessionStorage.getItem('userId') == 'aw666' && sessionStorage.getItem('userPs')== '123' ){
                        next()
                        
                }else{

                    this.$message.error('错了哦，这是一条错误消息')

    
                }
            }
        },
        
        
    ]
})

router.beforeEach((to,from,next)=>{
    // console.log(to,from,next);
    // if(to.path == '/list' ){
        next()
        
    // }
})

//全局后置路由
router.afterEach((to,from)=>{
    document.title = to.meta.title
    
})

export default router